﻿///***************************************************************
/// 시  스  템 : Updms.Common.Inc
/// 단위시스템 : INC
/// 계      층 : Presentation Layer
/// 프로그램명 : Top
/// 파  일  명 : Top.ascx.cs
/// 설      명 : 화면상단
///***************************************************************
/// 수정ID 일자       이름     내용
///---------------------------------------------------------------
/// CH001  2008-07-08 송시명   최초 작성
///***************************************************************
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;

using SMFramework.Configuration;
using SMFramework.Data;
using SMFramework.Utility;

using Base.Dac;
using Updms.Com.Exe;
using Updms.Usr.Exe;


namespace Updms.Common.Inc
{
	public partial class Top : System.Web.UI.UserControl
	{
		#region 전역영역
		
		protected string gs_id = "";
		protected string gs_nm = "";
		protected string gs_user_level = "";
		protected string gs_user_div = "";
		protected string gs_sm = "";
		protected string gs_group_nm = "";
		protected string gs_lang_set = "";

		Global global = new Global();
		
		#endregion

		#region Page_Load

		protected void Page_Load(object sender, EventArgs e)
		{
			ltr_ver.Text = WebConfig.Updms["App.Version"];
			gs_id			= Session["User_Id"].ToString().Trim();
			gs_nm			= Session["User_Nm"].ToString().Trim();
			gs_user_level	= Session["Access_Level"].ToString().Trim();
			gs_user_div		= Session["User_Div"].ToString().Trim();
			gs_group_nm		= Session["Group_Nm"].ToString().Trim();
			gs_lang_set		= Session["Lang_Set"].ToString().Trim();

			SetUserInfo();

			if (!String.IsNullOrEmpty(Request.QueryString["sm"]))
			{
				gs_sm = Request.QueryString["sm"].ToString();
			}
		}
		
		#endregion

		#region TabMenu

		public String TabMenu()
		{
			DataSet lo_ds = new DataSet();
			DataPack lo_dp = new DataPack();
			StringBuilder sb = new StringBuilder();

			lo_dp.AddProperty("ls_user_id", typeof(string), gs_id);
			lo_dp.AddProperty("ls_access_level", typeof(string), gs_user_level);
			lo_dp.AddProperty("ls_sm", typeof(string), gs_sm);
			lo_dp.AddProperty("ls_lang_set", typeof(string), gs_lang_set);
			
			using (Com1011m_NT _Com1011m_NT = new Com1011m_NT())
			{
				lo_ds.Merge(_Com1011m_NT.GetTabMenu(lo_dp));
			}
			int li_cnt = DataSetUtil.GetRowCount(lo_ds, "UPDMS_COM_PGM");

			sb.Append("<ul class=\"tab_menu\">");

			//탭 HTML 생성
			if (DataSetUtil.CheckRowCount(lo_ds, "UPDMS_COM_PGM"))
			{
				for (int i = 0; i < li_cnt; i++)
				{
					string pgm_class = DataSetUtil.GetFldStr(lo_ds, "UPDMS_COM_PGM", i, "Pgm_Class");
					string pgm_Nm = DataSetUtil.GetFldStr(lo_ds, "UPDMS_COM_PGM", i, "Pgm_Nm");
					string pgm_Url = DataSetUtil.GetFldStr(lo_ds, "UPDMS_COM_PGM", i, "Pgm_Url");
					string dir_depth = DataSetUtil.GetFldStr(lo_ds, "UPDMS_COM_PGM", i, "Dir_Depth");
					string selected = DataSetUtil.GetFldStr(lo_ds, "UPDMS_COM_PGM", i, "Selected");

					string tab_html_s = "<li><span>";
					string link = "<a href=";
					string tab_html_e = "</a></span></li>";

					//대표프로그램이 없으면 빈링크
					if (pgm_class == "")
					{
						link = link + "\"#\">" + pgm_Nm;
					}
					else
					{
						link = link + "\"../" + pgm_class + "/" + pgm_Url + "?sm=" + dir_depth + "\">" + pgm_Nm;
					}

					//선택된 경우
					if (selected == "Y")
					{
						tab_html_s = tab_html_s.Replace("<li>", "<li class=\"selected\">");
					}

					sb.Append(tab_html_s + link + tab_html_e);

					if (i < li_cnt - 1)
					{
						sb.Append("\r\n\t\t\t\t" + "<li class=\"margin\"></li>");
					}
				}
			}

			sb.Append("\r\n\t\t\t</ul>");

			return sb.ToString();
		}
		
		#endregion

		#region SetUserInfo
		
		//사용자정보(화면 우상단)
		private void SetUserInfo()
		{
			int li_todo_cnt = 0;
			string ls_todo_cnt = "";

			using (Usr1010m_NT _Usr1010m_NT = new Usr1010m_NT())
			{
				li_todo_cnt = _Usr1010m_NT.GetToDoCount(gs_id);
			}

			if (li_todo_cnt > 0)
			{
				ls_todo_cnt = "<a href=\"/updms/Usr/Usr1010m.aspx?sm=" + global.GetDirDepth("Usr1010m") + "\"><span class=\"todo\">" + li_todo_cnt.ToString("#,##0") + "</span></a>";
			}
			else
			{
				ls_todo_cnt = "<span class=\"todo\">0</span>";
			}

			lbl_user_info.Text = " [ " + gs_id + " ] [ TO-DO : " + ls_todo_cnt + " ] [" + gs_user_level + "] [ " + gs_group_nm + " ]";
			img_flag.ImageUrl = "../Images/" + gs_lang_set + ".png";
			img_flag.ToolTip = gs_lang_set;
		}
		
		#endregion
			
	}
}